<template>
  <el-upload
    style="height: 0px"
    ref="upload"
    :limit="1"
    action=""
    :on-change="uploadChange"
    :http-request="handleUpload"
    :auto-upload="true"
    :show-file-list="false"
  >
    <slot></slot>
  </el-upload>
  <!-- <el-upload
    class="upload-demo"
    action=""
    :auto-upload="false"
    :on-change="uploadChange"
    :limit="1"
    :show-file-list="false"
  >
    <slot></slot>
  </el-upload> -->
</template>

<script setup>
import * as xlsx from 'xlsx/xlsx.mjs'
// import { reqInsertGoods, reqInsertOneType, reqInsertTwoType } from '@/api/goods'
const handleUpload = () => {}
const uploadChange = async (file) => {
  const dataBinary = await readFile(file.raw)
  const workBook = xlsx.read(dataBinary, {
    type: 'binary',
    cellDates: true
  })
  const workSheet = workBook.Sheets[workBook.SheetNames[0]]
  const data = xlsx.utils.sheet_to_json(workSheet)
  console.log(data)
}
const readFile = (file) => {
  return new Promise((resolve) => {
    const reader = new FileReader()
    reader.readAsBinaryString(file)
    reader.onload = (ev) => {
      resolve(ev.target.result)
    }
  })
}
</script>
